# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=vala
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.50.0
pkgrel=1
pkgdesc="Compiler for the GObject type system (mingw-w64)"
arch=('any')
url="https://wiki.gnome.org/Projects/Vala"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "help2man")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-graphviz")
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-change-pkg-config-invocations.mingw.patch
        002-use_time_s_functions_on_windows.mingw.patch)
sha256sums=('838adc50ac08881e06cf233fefd93740dec1530312cc1cf12c36d4e0e87d3071'
            'c588a3a69097aae30ada1d543001d5029865b1dd1f46132d9e60d12e1833b325'
            '1309ae50867b81ea5d170487b36443a41c8dfee202213198c980a133300d6f9a')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-change-pkg-config-invocations.mingw.patch
  patch -p1 -i ${srcdir}/002-use_time_s_functions_on_windows.mingw.patch
  autoreconf -ivf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="${pkgdir}" install
  
  # Move libvalaccodegen.dll to correct directory
  mv "${pkgdir}${MINGW_PREFIX}"/lib/bin/libvalaccodegen.dll "${pkgdir}${MINGW_PREFIX}"/bin/libvalaccodegen.dll
  rm -rf "${pkgdir}${MINGW_PREFIX}"/lib/bin

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}

